package com.astrob.TileSource;

import org.osmdroid.tileprovider.MapTile;
import org.osmdroid.tileprovider.tilesource.OnlineTileSourceBase;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;


public class BaiDRMapsTileSource extends OnlineTileSourceBase {
    /**
     * @param aName                a human-friendly name for this tile source  自定图源义名字，会在手机外部存储中新建以该名字命名的文件夹，瓦片存储在其中
     * @param aZoomMinLevel        the minimum zoom level this tile source can provide  最小缩放级别
     * @param aZoomMaxLevel        the maximum zoom level this tile source can provide  最大缩放级别
     * @param aTileSizePixels      the tile size in pixels this tile source provides  瓦片质量 （256）
     * @param aImageFilenameEnding the file name extension used when constructing the filename  瓦片格式（jpg[有损压缩率高、不透明]、png[无损、透明]）
     * @param aBaseUrl             the base url(s) of the tile server used when constructing the url to download the tiles  下载瓦片的链接（前缀）
     */
    public BaiDRMapsTileSource(String aName, int aZoomMinLevel, int aZoomMaxLevel, int aTileSizePixels,
                               String aImageFilenameEnding, String[] aBaseUrl) {
        super(aName, aZoomMinLevel, aZoomMaxLevel, aTileSizePixels, aImageFilenameEnding, aBaseUrl);
    }


    //http://online0.map.bdimg.com/onlinelabel/?qt=tile&x=707&y=217&z=12&styles=pl&udt=20151021&scaler=1&p=1
    //http://online0.map.bdimg.com/onlinelabel/?qt=tile&styles=pl&udt=20151021&scaler=1&p=1&x=54918&y=26785&z=16  --错误的
    @Override
    public String getTileURLString(MapTile aTile) {
        int halfTileNum = (int) Math.pow(2, aTile.getZoomLevel() - 1);
        int tilePositionX = aTile.getX() - halfTileNum;
        int tilePositionY = aTile.getY() + halfTileNum;

        String url = getBaseUrl() + "&x=" + tilePositionX + "&y=" + tilePositionY + "&z=" + aTile.getZoomLevel();
        return url;
    }

//    center : ol.proj.transform([ 108.945731,34.382717], 'EPSG:4326', 'EPSG:3857')
//    谷歌地图和天地图、高德地图   EPSG:4326
//    百度地图      EPSG：3857

    //https://www.cnblogs.com/dulvyizhihua/archive/2011/06/11/2077853.html   --开源的坐标投影转化

}